nice_things/fs/basename.sh
basename
Since 0.3.0 · Source
import "{ basename }" from nice_things/fs/basename.sh
Synopsisbasename <pathname> [<suffix>]
Configuration
–
Description
Print <pathname> with any leading directory components removed. If specified, also remove a trailing <suffix>.
This is a pure sh implementation of the utility specified in POSIX.
Options
–
Operands
<pathname>: A path name.<suffix>: An optional suffix.
Stdin
–
Stdout
The resulting filename is printed to stdout, trailed by a line-feed character.
Stderr
–
Exit status0: Successful completion.
Abort
–
Usage examples
# Get name of current program
cmd=$(basename "$0")
# Print file name with extension removed
basename include/stdio.h .h # stdio